package com.dextrys.testing.seleniumdemo.driver;

import java.util.ArrayList;
import java.util.List;

import com.dextrys.testing.seleniumdemo.factory.TestCaseFactory;
import com.dextrys.testing.seleniumdemo.jxl.IExcelAccess;
import com.dextrys.testing.seleniumdemo.jxl.impl.ExcelAccessImpl;
import com.dextrys.testing.seleniumdemo.util.Config;

import jxl.Sheet;
import jxl.Workbook;

public class TestDriver {

	public static IExcelAccess ea;

	public static void main(String[] args) {
		// Get TestCase List
		ea = new ExcelAccessImpl();
		TestCaseFactory factory = new TestCaseFactory();
		Workbook workbook = ea.getWorkBook(Config.getTestSuiteFile());
		Sheet sheet = workbook.getSheet(0);
		List<String> caseList = new ArrayList<String>();
		List<String> dataList = new ArrayList<String>();
		for (int p = 1; p < sheet.getRows(); p++) {
			String mycase = sheet.getCell(1, p).getContents();
			String mydata = sheet.getCell(2, p).getContents();
			String myrun = sheet.getCell(3, p).getContents();
			if (myrun != null & !myrun.toLowerCase().equals("n")) {
				caseList.add(mycase);
				dataList.add(mydata);
			}
		}
		workbook.close();
		
		// Cycle Driver
		for (int n = 0; n < caseList.size(); n++) {
			String caseName = caseList.get(n);
			String dataName = dataList.get(n);
			String caseFile = Config.getTestCasePath()
				+ caseName + ".xls";
			Workbook caseBook = ea.getWorkBook(caseFile);
			factory.generateTestCase(caseBook, dataName);
		}
	}
}
